package Collections类;

public class Person implements Comparable<Person>  {
    private String name;
    private int ages;

    // public static int compare(int x, int y) {
    //     return (x < y) ? -1 : ((x == y) ? 0 : 1);
    // }

    //重写排序规则
    @Override
    public int compareTo(Person o) {
        //升序排列
        //return this.ages-o.ages;
        //降序排序
        return o.ages-this.ages;
        //返回值为0，表示元素排序相同
        //return 0;
    }

    public Person(String name, int ages) {
        this.name = name;
        this.ages = ages;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", ages=" + ages +
                '}';
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAges() {
        return ages;
    }

    public void setAges(int ages) {
        this.ages = ages;
    }


}
